package net.maku.aop;

import org.aspectj.lang.ProceedingJoinPoint;  
import org.aspectj.lang.annotation.*;  
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import jakarta.servlet.http.HttpServletRequest;
import net.maku.bean.model.MyException;
import net.maku.utils.TokenUtils;  
@Aspect  
@Component  
public class SessionAspect {  
    @Pointcut("@annotation(net.maku.aop.Session)")  
    public void pointCut(){}  
    
    @Before("pointCut()")  
    public void before() {  
        System.out.println("前置通知..."); 
        //ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        //if (attributes != null) {
            //HttpServletRequest request = attributes.getRequest();
            //System.out.println( TokenUtils.getAccessToken(request) );
            //System.out.println("token: " + TokenUtils.getAccessToken(request));
            // 在这里可以获取到HttpServletRequest对象，进行你需要的操作
        //}
        //throw new MyException("没有登录态");
        //System.out.println( TokenUtils.getAccessToken(null) );
        
        TokenUtils.getUserInfo();
        //TokenUtils.getAccessToken();
    }  
    @After("pointCut()")  
    public void after() {  
        System.out.println("后置通知...");  
    }  
    
    /*
    @Around("pointCut()")  
    public void around(ProceedingJoinPoint point) throws Throwable {  
        System.out.println("环绕通知前...");  
        point.proceed();  
        System.out.println("环绕通知后...");  
    }*/
}
